﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnitySheet;

/// <summary>
/// 有具体内容的单元格
/// </summary>
public class ContentCell : Cell {
    /// <summary>
    /// 单元格的内容
    /// </summary>
    public CellContent cellContent
    {
        get;
        protected set;
    }
    public Image icon;
    public Text description;

    protected override void Start()
    {
        base.Start();
        onSelectOneCell += OnSelected;
        onDeselectOneCell += OnDeselected;
    }
    public void SetContent(CellContent content)
    {
        if (content == null)
        {
            cellContent = null;
            icon.sprite = null;
            SetDescription(null);
            return;
        }
        else if (cellContent == null || cellContent.contentType != content.contentType)
        {
            CellContent cc = cellContent;
            cellContent = content;
            icon.sprite = cellContent.contentType == CellContent.CellContentType.DropDown ? SheetSystemManager.sheetSystemManager.setCell.dropDownImage : SheetSystemManager.sheetSystemManager.setCell.textImage;
            content.onDescriptionChanged += SetDescription;
            SetDescription(content.description);
            if (cc != null)
            {
                cc.OnSelected(false);
            }
        }
        cellContent.OnSelected(true);
    }

    void SetDescription(string des)
    {
        description.text = des;
    }

    private void OnSelected(Cell cell)
    {
    }

    private void OnDeselected(Cell cell)
    {
    }
}
